<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

class CreateVideoCommentTable extends Migration
{
    private $tableName = 'video_comments';
    private $tableComment = '视频评论表';
    private $primaryKey = 'id';

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create($this->tableName, function (Blueprint $table) {
            $table->increments(env('DB_CONNECTION') == 'oracle' ? strtoupper($this->primaryKey) : $this->primaryKey)->comment('评论id');
            $table->unsignedInteger('video_id')->comment('视频id');
            $table->unsignedInteger('uid')->comment('作者id');
            $table->unsignedTinyInteger('status')->comment('状态，1正常，2待审核')->default(1);
            $table->string('content', 3000)->comment('评论内容')->nullable();
            $table->string('title', 100)->comment('标题')->nullable();
            $table->unsignedInteger('parent_cid')->comment('父级评论id')->default(0);
            $table->unsignedInteger('zan')->comment('赞数')->default(0);
            $table->timestamps();
            if (env('DB_CONNECTION') == 'oracle') {
                $table->comment = $this->tableComment;
            }
        });

        if (env('DB_CONNECTION') == 'mysql') {
            DB::statement("ALTER TABLE `" . DB::getTablePrefix() . $this->tableName . "` comment '{$this->tableComment}'");
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists($this->tableName);
        if (env('DB_CONNECTION') == 'oracle') {
            $sequence = DB::getSequence();
            $sequence->drop(strtoupper($this->tableName . '_comment_id_SEQ'));
        }
    }
}

